package com.test.reggie.model.jiesuan;

import com.test.reggie.base.BaseObserver;
import com.test.reggie.base.BasePresenter;
import com.test.reggie.bean.AddAddressBean;
import com.test.reggie.bean.ShoppingCartListBean;
import com.test.reggie.bean.StringBean;

import java.util.Map;

public class JiesuanPresenter extends BasePresenter<JiesuanView> {
    public JiesuanPresenter(JiesuanView baseView) {
        super(baseView);
    }

    /**
     * 查询默认地址
     *
     * @param userId
     */
    public void getDefault(String userId) {
        addDisposable(apiServer.getDefault(userId), new BaseObserver<AddAddressBean>() {
            @Override
            public void onSuccess(AddAddressBean bean) {
                baseView.getDefaultSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 查看购物车
     *
     * @param userId
     */
    public void shoppingCartList(String userId) {
        addDisposable(apiServer.shoppingCartList(userId), new BaseObserver<ShoppingCartListBean>() {
            @Override
            public void onSuccess(ShoppingCartListBean bean) {
                baseView.shoppingCartListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 用户下单
     *
     * @param map
     */
    public void submitOrders(Map<String, Object> map) {
        addDisposable(apiServer.submitOrders(map), new BaseObserver<StringBean>() {
            @Override
            public void onSuccess(StringBean bean) {
                baseView.submitOrdersSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
